package cn.outsourcing.supermarket.controller;

import cn.outsourcing.supermarket.common.Result;
import cn.outsourcing.supermarket.common.utils.ResultUtils;
import cn.outsourcing.supermarket.dto.CategoryGoodsPageDTO;
import cn.outsourcing.supermarket.service.HiolabsCategoryService;
import cn.outsourcing.supermarket.service.HiolabsGoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 分类有关前端控制器
 *
 * @author gzkemays
 * @since 2021-10-20
 */
@RestController
@RequestMapping("/catalog")
public class HiolabsCategoryController {
  @Resource private HiolabsCategoryService categoryService;
  @Resource private HiolabsGoodsService goodsService;

  @GetMapping("/index")
  public Result index() {
    return ResultUtils.simpleResult(categoryService.getCategoryList());
  }

  @GetMapping("/current")
  public Result current(@RequestParam(value = "id") Integer id) {
    return ResultUtils.simpleResult(categoryService.getCategoryDetail(id));
  }

  @PostMapping("/currentlist")
  public Result currentList(@RequestBody CategoryGoodsPageDTO entity) {
    return ResultUtils.pageResult(goodsService.getCategoryGoods(entity, false)).defaultError();
  }

  @PostMapping("/homeList")
  public Result homeList(@RequestBody CategoryGoodsPageDTO entity) {
    return ResultUtils.pageResult(goodsService.getCategoryGoods(entity, true)).defaultError();
  }
}
